const path = require('path');
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');

const { pathAlias } = require('./my-config');

function resolve(dir) {
	return path.join(__dirname, dir);
}

module.exports = {
	productionSourceMap: false,
	devServer: {
		port: 2000,
		open: false,
		overlay: {
			warnings: true,
			errors: true,
		},
	},
	outputDir: 'dist',
	css: {
		loaderOptions: {
			postcss: {
				plugins: [
					autoprefixer(),
					pxtorem({
						rootValue: 37.5,
						propList: ['*'],
					}),
				],
			},
		},
	},

	//生产环境去log
	configureWebpack: (config) => {
		if (process.env.NODE_ENV === 'production') {
			config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
		}
	},

	//配置别名
	chainWebpack: (config) => {
		let alias = config.resolve.alias;
		for (let index in pathAlias) {
			alias.set(index, resolve(pathAlias[index]));
		}
	},
};
